#!/bin/sh

start() {
psplash-write "PROGRESS 75" 
if test -z "$DBUS_SESSION_BUS_ADDRESS" ; then
        eval `dbus-launch --sh-syntax`
        echo "D-Bus per-session daemon address is: $DBUS_SESSION_BUS_ADDRESS"
fi
export DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS"

ntpd

TS_CALIBRATION_FILE=/etc/pointercal
if [ ! -f $TS_CALIBRATION_FILE ];then
        export TSLIB_TSDEVICE=/dev/input/touchscreen0
        ts_calibrate 
fi

export XDG_RUNTIME_DIR=/tmp/runtime-root
export QT_QPA_PLATFORM=linuxfb
export QT_QPA_EGLFS_TSLIB=1
export TSLIB_CALIBFILE="/etc/pointercal"
export TSLIB_TSDEVICE="/dev/input/event1"

psplash-write "PROGRESS 95" 
/usr/bin/mxapp2 --plugin tslib:$TSLIB_TSDEVICE &

psplash-write "QUIT" 
}

stop() {
	killall mxapp2
}

case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        *)
                echo "Usage: $0 {start| stop|restart}"
                exit 1
esac

exit $?
